package com.example.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.entity.Saler;

import com.service.imp.BusinessServiceImpl;
import java.io.IOException;

@WebServlet(name = "RegisterServlet", value = "/RegisterServlet")
public class RegisterServlet extends HttpServlet {
//    private String message;
    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try{
            request.setCharacterEncoding("UTF-8");
            String salerName = request.getParameter("salername");
            String accountName = request.getParameter("username");
            String password = request.getParameter("password");
            String address = request.getParameter("address");
            Saler saler = new Saler(salerName,accountName,password,address);


            BusinessServiceImpl service = new BusinessServiceImpl();
            String message = service.addSaler(saler);
            request.setAttribute("message",message);
            request.getRequestDispatcher("/message.jsp").forward(request, response);//这里要跳转到首页，并且显示欢迎您，，，待修改

        }catch(Exception e){
            e.printStackTrace();
            request.setAttribute("message", "注册失败");
            request.getRequestDispatcher("/message.jsp").forward(request, response);
        }
    }

}